package com.zjuh.taofood.biz.dao.ibatis;

import java.util.Date;

import com.zjuh.taofood.biz.dao.TaobaoItemDescriptionDAO;
import com.zjuh.taofood.biz.domain.taobao.TaobaoItemDescriptionDO;

public class TaobaoItemDescriptionDAOIbatis extends BaseIbatisDAO implements TaobaoItemDescriptionDAO {

	public long create(TaobaoItemDescriptionDO taobaoItemDescription) {
		return (Long)this.getSqlMapClientTemplate().insert("TaobaoItemDescriptionDAO.create", taobaoItemDescription);
	}

	public void delete(long id) {
		this.getSqlMapClientTemplate().update("TaobaoItemDescriptionDAO.delete", id);
	}

	public void update(TaobaoItemDescriptionDO taobaoItemDescription) {
		this.getSqlMapClientTemplate().update("TaobaoItemDescriptionDAO.update", taobaoItemDescription);
	}

	public TaobaoItemDescriptionDO queryById(long id) {
		return (TaobaoItemDescriptionDO)this.getSqlMapClientTemplate().queryForObject("TaobaoItemDescriptionDAO.queryById", id);
	}
	
	private Long queryIdByItemId(long itemId) {
		return (Long)this.getSqlMapClientTemplate().queryForObject("TaobaoItemDescriptionDAO.queryIdByItemId", itemId);
	}

	@Override
	public void insertOrUpdateByItemId(TaobaoItemDescriptionDO taobaoItemDescription) {
		Long id = queryIdByItemId(taobaoItemDescription.getItemId());
		if (id == null) {
			create(taobaoItemDescription);
		} else {
			taobaoItemDescription.setId(id);
			Date now = new Date();
			taobaoItemDescription.setGmtCreate(now);
			taobaoItemDescription.setGmtCreate(now);
			update(taobaoItemDescription);
		}
	}

	@Override
	public TaobaoItemDescriptionDO queryByItemId(long itemId) {
		return (TaobaoItemDescriptionDO)this.getSqlMapClientTemplate().queryForObject("TaobaoItemDescriptionDAO.queryByItemId", itemId);
	}


	
}
